/**
 * Created by hcadmin on 16/5/20.
 */
define([
    "jquery",
    "IO",
    "UPLOADUI",
    "UPLOAD",
    "jqueryUI",
    "bootbox"
], function ($, IO, upui, up, jui, bootbox, definebt) {
    $(function () {
        gettable();

        $("#btnSearch").click(function(){
            gettable();
        });

    });

    function gettable(){

        var grid;
        //每列数据列性
        var columns = [
            {
                title: '服务人',
                dataIndex: 'first_name',
                dataSource: function (data, datarow, gridobj, current_column) {

                    return "<span>" + data[datarow]['babySisterVo'].first_name +data[datarow]['babySisterVo'].second_name+ "</span>";
                }
            },
            {
                title: '服务客户',
                dataIndex: 'realname',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].realname+ "</span>";
                }
            },
            {
                title: '服务类别',
                dataIndex: 'typecount',
                dataSource: function (data, datarow, gridobj, current_column) {
                    //return "<span>" + data[datarow].services + "</span>";
                    return "<span>"+"月嫂"+"</span>";
                }
            },
            {
                title: '服务费用',
                dataIndex: 'cost',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow]['babySisterVo'].cost + "</span>";

                }
            },
            {
                title: '服务周期',
                dataIndex: 'server_month',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow].server_month + "</span>";

                }
            },
            {
                title: '月搜公司',
                dataIndex: 'company_name',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow]['babySisterVo']['company'].company_name + "</span>";

                }
            },
            {
                title: '问答评分',
                dataIndex: 'score',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<span>" + data[datarow]['babySisterVo'].score + "</span>";

                }
            },
            {
                title: '状态',
                dataIndex: 'status',
                dataSource: function (data, datarow, gridobj, current_column) {
                    if(data[datarow].status==0){
                        return "<span>" + "待审核" + "</span>";
                    }
                    else if(data[datarow].status==1){
                        return "<span>" + "过审核待付款" + "</span>";
                    }
                    else if(data[datarow].status==2){
                        return "<span>" + "已支付服务中" + "</span>";
                    }
                    else if(data[datarow].status==3){
                        return "<span>" + "已完成" + "</span>";
                    }
                    else if(data[datarow].status==-1){
                        return "<span>" + "已拒绝" + "</span>";
                    }
                }
            },
            {
                title: '详情',
                dataIndex: 'action',
                dataSource: function (data, datarow, gridobj, current_column) {
                    return "<a href='#' status="+data[datarow].status+" baby_sister_appointment_id="+data[datarow].baby_sister_appointment_id+" class='details'><span style='color: #6ab7ad;'>" + "详情" + "</span></a>";
                }
            }
        ];
        //数组初始化

        function dataInit() {

            grid = new Grid("/api/baby_sister_appointment/list", $("#table_my_toast"), $("#paging_my_toast"), 1, 10, columns, get_input_param(), 10);

            //初始化
            grid.Init();
        }

        //获取输入框内容
        function get_input_param() {
            var type=$(".selecttype option:selected").val()=='-1'?"":$(".selecttype option:selected").val();
            var company_id=$(".selectcompany option:selected").val()=='-1'?"":$(".selectcompany option:selected").val();
            var status=$(".selectstaus option:selected").val()=='-2'?"":$(".selectstaus option:selected").val();
            var param="type="+type+"&company_id="+company_id+"&status="+status;
            return param;
        }
        dataInit();
    }
    $(document).on('click','.details',function(){
        var baby_sister_appointment_id=$(this).attr('baby_sister_appointment_id');
        var status=$(this).attr('status');
        //未接单
        if(status==0){
            location.href='/96053/order_no_single?baby_sister_appointment_id='+baby_sister_appointment_id;
        }
        //已接单
        else {
            location.href='/96053/order_yes_single?baby_sister_appointment_id='+baby_sister_appointment_id;
        }
    })
});